/*
https://leetcode-cn.com/problems/mirror-reflection/solution/jing-mian-fan-she-by-leetcode/
 */
public class Solution858 {
    public int mirrorReflection(int p, int q) {
        if (q==0){
            return 0;
        }
        int t=p*q/gcd(p,q);
        if (t/q%2==0){
            return 2;
        }
        if (t/p%2==1){
            return 1;
        }else {
            return 0;
        }
    }

    int gcd(int a,int b){
        if (a<b){
            int t=a;
            a=b;
            b=t;
        }
        return a%b==0?b:gcd(b,a%b);
    }

    public static void main(String[] args) {
        System.out.println(new Solution858().mirrorReflection(2,1));
    }
}
